// FCExportImport.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string.h>
#include <stdlib.h>
#include <direct.h>
#include "FCExportImport.h"
#include "FCMeshCodec.h"
char inputFileNameDae[LSTRL];
char outputFileNameDae[LSTRL];
const char* fileNameLog = "FCTestLog.txt";
bool isImport = false;
int DoTestExpImp();
comms::cMeshConatainer *Import3DAE(const char *file);

void ShowHelp()
{
	fprintf(stderr, "Unknown command line argument(s). \n");
	fprintf(stderr, "Usage: FCExpImpTest.exe -i <filenameIn.dae>\n");
	fprintf(stderr, "Usage: FCExpImpTest.exe -e <filenameIn.dae> [<filenameOut.dae>]\n");
	fprintf(stderr, " <filenameIn.dae>: Set the filename of the input collada file.\n");
	fprintf(stderr, " <filenameOut.dae>: Set the filename of the output collada file.\n");
	fflush(stderr);
	exit(-1);
}

void ProcessCommandLine(int argc, char *argv[])
{
	--argc; ++argv;
	int n = argc;
	while (argc > 0)
	{
		if (argv[0][0] == '-')
		{
			++(argv[0]);
			if(argv[0][0]=='i')
				isImport = true;
			else
				if(argv[0][0]=='e')
					isImport = false;
				else
				{
					ShowHelp();
				}
			if(argc==1)
				ShowHelp();
		}
		++argv;
		--argc;
		if(argc==n-1)
		{
			if(argv[0]!=NULL)
				strcpy_s(inputFileNameDae,LSTRL,argv[0]);
		}
		else if(argc==n-2)
		{
			if(argv[0]!=NULL)
			  strcpy_s(outputFileNameDae,LSTRL,argv[0]);
		}
	}
}

int main(int argc, char* argv[])
{
	ProcessCommandLine(argc, argv);
	/*InitCollada();*/
	DoTestExpImp();
	/*DeInitCollada();*/
	return 0;
}
comms::cMeshConatainer *Import3DAE(const char *file)
{
	comms::FCMeshCodec *pFCMeshCodec = new comms::FCMeshCodec;
	comms::cMeshConatainer *meshCntr = pFCMeshCodec->Decode(file);
	delete pFCMeshCodec;
	return meshCntr;
}

void CheckMeshContainer(comms::cMeshConatainer  *mesh)
{
}
	
int DoTestExpImp()
{
	if(isImport)
	{
		fprintf(stdout, "Import: \n");
		_chdir("Samples");
		comms::cMeshConatainer *mesh = Import3DAE(inputFileNameDae);
		CheckMeshContainer(mesh);
		delete mesh;
	}
	return 0;
}